#include <stdio.h>
#include <string.h>

#define MAX_LEN 64

char buf[MAX_LEN];

void getchar_demo() {
    char ch;

    printf("getchar\n");

    /* EOF == ctrl+D */
    /* return when read \n, include \n */
    while ((ch = getchar()) != EOF) {
        printf("%c", ch);
    }
}

void fgets_demo() {
    char buf[MAX_LEN];

    printf("fgets\n");

    /* return when read enough bytes, or \n, include \n */
    /* return NULL when read EOF or encounter exception */
    while (fgets(buf, sizeof(buf), stdin) != NULL) {
        printf("%s", buf);
        memset(buf, 0, sizeof(buf));
    }
}

int main(int argc, char *argv[]) {

    if (argc != 2) {
        perror("Usage: ./stdio type");
        return -1;
    }

    if (strcmp(argv[1], "getchar") == 0) {
        getchar_demo();
    } else if (strcmp(argv[1], "fgets") == 0) {
        fgets_demo();
    } else if (strcmp(argv[1], "scanf") == 0) {
        // scanf_demo();
    }
}